package com.supermap.census.ui.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.supermap.census.R;
import com.supermap.census.app.SharedPreferencesManager;
import com.supermap.census.event.EventBusModel;
import com.supermap.census.ui.AboutUsActivity;
import com.supermap.census.ui.AccountInfoActivity;
import com.supermap.census.ui.CertificateActivity;
import com.supermap.census.ui.HelpActivity;
import com.supermap.census.ui.LoginActivity;
import com.supermap.census.utils.IntentUtils;

import org.greenrobot.eventbus.EventBus;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

public class MyselfFragment extends Fragment {


    @Bind(R.id.userHeadView)
    CircleImageView userHeadView;
    @Bind(R.id.userNameTv)
    TextView userNameTv;
    @Bind(R.id.certificate)
    TextView certificate;
    @Bind(R.id.account_info)
    TextView accountInfo;
    @Bind(R.id.help)
    TextView help;
    @Bind(R.id.about_us)
    TextView aboutUs;
    @Bind(R.id.quit_btn)
    Button quitBtn;

    public MyselfFragment() {
        // Required empty public constructor
    }

    public static MyselfFragment newInstance() {
        MyselfFragment fragment = new MyselfFragment();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_myself, container, false);
        initView(view);
        ButterKnife.bind(this, view);
        return view;

    }

    private void initView(View view) {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.userHeadView, R.id.userNameTv, R.id.certificate, R.id.account_info, R.id.help, R.id.about_us, R.id.quit_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.userHeadView:
                IntentUtils.into(getContext(), AccountInfoActivity.class);
                break;
            case R.id.userNameTv:
                break;
            case R.id.certificate:
                IntentUtils.into(getContext(), CertificateActivity.class);
                break;
            case R.id.account_info:
                IntentUtils.into(getContext(), AccountInfoActivity.class);
                break;
            case R.id.help:
                IntentUtils.into(getContext(), HelpActivity.class);
                break;
            case R.id.about_us:
                IntentUtils.into(getContext(), AboutUsActivity.class);
                break;
            case R.id.quit_btn:
                quitLogin();
                break;
        }
    }

    /**
     * 退出登录
     */
    private void quitLogin() {
        SharedPreferencesManager.saveUserLogin(false);
        EventBusModel eventBusModel = new EventBusModel();
        eventBusModel.setFinish(true);
        EventBus.getDefault().post(eventBusModel);
        //
        IntentUtils.into(getContext(), LoginActivity.class);

    }
}
